home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Misc Servers / Zope.exe / DTTEST.PY < prev    next >
Encoding:
Python Source  |  1999-03-22  |  20.5 KB  |  599 lines

  1. ##############################################################################
  2. # Zope Public License (ZPL) Version 1.0
  3. # -------------------------------------
  4. # Copyright (c) Digital Creations.  All rights reserved.
  5. # This license has been certified as Open Source(tm).
  6. # Redistribution and use in source and binary forms, with or without
  7. # modification, are permitted provided that the following conditions are
  8. # met:
  9. # 1. Redistributions in source code must retain the above copyright
  10. #    notice, this list of conditions, and the following disclaimer.
  11. # 2. Redistributions in binary form must reproduce the above copyright
  12. #    notice, this list of conditions, and the following disclaimer in
  13. #    the documentation and/or other materials provided with the
  14. #    distribution.
  15. # 3. Digital Creations requests that attribution be given to Zope
  16. #    in any manner possible. Zope includes a "Powered by Zope"
  17. #    button that is installed by default. While it is not a license
  18. #    violation to remove this button, it is requested that the
  19. #    attribution remain. A significant investment has been put
  20. #    into Zope, and this effort will continue if the Zope community
  21. #    continues to grow. This is one way to assure that growth.
  22. # 4. All advertising materials and documentation mentioning
  23. #    features derived from or use of this software must display
  24. #    the following acknowledgement:
  25. #      "This product includes software developed by Digital Creations
  26. #      for use in the Z Object Publishing Environment
  27. #      (http://www.zope.org/)."
  28. #    In the event that the product being advertised includes an
  29. #    intact Zope distribution (with copyright and license included)
  30. #    then this clause is waived.
  31. # 5. Names associated with Zope or Digital Creations must not be used to
  32. #    endorse or promote products derived from this software without
  33. #    prior written permission from Digital Creations.
  34. # 6. Modified redistributions of any form whatsoever must retain
  35. #    the following acknowledgment:
  36. #      "This product includes software developed by Digital Creations
  37. #      for use in the Z Object Publishing Environment
  38. #      (http://www.zope.org/)."
  39. #    Intact (re-)distributions of any official Zope release do not
  40. #    require an external acknowledgement.
  41. # 7. Modifications are encouraged but must be packaged separately as
  42. #    patches to official Zope releases.  Distributions that do not
  43. #    clearly separate the patches from the original work must be clearly
  44. #    labeled as unofficial distributions.  Modifications which do not
  45. #    carry the name Zope may be packaged in any form, as long as they
  46. #    conform to all of the clauses above.
  47. # Disclaimer
  48. #   THIS SOFTWARE IS PROVIDED BY DIGITAL CREATIONS ``AS IS'' AND ANY
  49. #   EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  50. #   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  51. #   PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL DIGITAL CREATIONS OR ITS
  52. #   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53. #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  54. #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  55. #   USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  56. #   ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  57. #   OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  58. #   OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. #   SUCH DAMAGE.
  60. # This software consists of contributions made by Digital Creations and
  61. # many individuals on behalf of Digital Creations.  Specific
  62. # attributions are listed in the accompanying credits file.
  63. ##############################################################################
  64. """Document Template Tests
  65. """
  66.  
  67. __rcs_id__='$Id: DTtest.py,v 1.12 1999/03/22 23:19:42 jim Exp $'
  68. __version__='$Revision: 1.12 $'[11:-2]
  69.  
  70. from DocumentTemplate import *
  71. import sys
  72.  
  73. class Bruce:
  74.    def __str__(self): return 'bruce'
  75.    def __int__(self): return 42
  76.    def __float__(self): return 42.0
  77.    def keys(self): return ['bruce']*7
  78.    def values(self): return [self]*7
  79.    def items(self): return [('bruce',self)]*7
  80.    def __len__(self): return 7
  81.    def __getitem__(self,index):
  82.        if (type(index) is type(1) and 
  83.            (index < 0 or index > 6)): raise IndexError, index
  84.        return self
  85.    isDocTemp=0
  86.    def __getattr__(self,name):
  87.        if name[:1]=='_': raise AttributeError, name
  88.        return self
  89.    
  90. bruce=Bruce()    
  91.  
  92. class arg:
  93.     def __init__(self,nn,aa): self.num, self.arg = nn, aa
  94.  
  95. class argv:
  96.     def __init__(self):
  97.         import sys
  98.         args=self.args=[]
  99.         for aa in sys.argv[1:]: args.append(arg(len(args)+1,aa))
  100.  
  101.     def items(self):
  102.         return map(lambda a: ('spam%d' % a.num, a), self.args)
  103.  
  104.     def values(self): return self.args
  105.  
  106. def test1():
  107.  
  108.     aa=argv()
  109.  
  110.     ss=String(
  111.         """\
  112.         %(comment)[ blah %(comment)]
  113.         <html><head><title>Test of documentation templates</title></head>
  114.         <body>
  115.         %(if args)[
  116.         <dl><dt>The arguments to this test program were:<p>
  117.         <dd>
  118.         <ul>
  119.         %(in args)[
  120.           <li>Argument number %(num)d was %(arg)s
  121.         %(in args)]
  122.         </ul></dl><p>
  123.         %(if args)]
  124.         %(else args)[
  125.         No arguments were given.<p>
  126.         %(else args)]
  127.         And thats da trooth.
  128.         </body></html>
  129.         """)
  130.  
  131.     print ss(aa)
  132.  
  133.     print 'num inaccessible:'
  134.     # ss.names({'args':'args'})
  135.     print ss(aa)
  136.  
  137.     print 'quoted source:'
  138.     print str(ss)
  139.  
  140.     try:
  141.         ss(hello=1,world=2)
  142.         print 'test if test failed'
  143.     except: pass
  144.  
  145.     # Test nested templates
  146.     a=arg(42,'bruce')
  147.     a.header=HTML("<!--#var arg--> data <!--#var num fmt=%d-->:\n")
  148.     print String("%(header)s number: %(num)d")(a)
  149.  
  150. def test2():
  151.     # test1()
  152.  
  153.     aa=argv()
  154.  
  155.     print HTML(
  156.         '''\
  157.         <html><head><title>Test of documentation templates</title></head>
  158.         <body>
  159.         <!--#if values-->
  160.           The arguments were:
  161.           <!--#in
  162.           values-->
  163.               <!--#var
  164.               sequence-roman-->.
  165.               Argument <!--#var
  166.               num fmt=d--> was <!--#var arg-->
  167.           <!--#/in values-->
  168.         <!--#else values-->
  169.           No arguments were given.<p>
  170.         <!--#/if values-->
  171.         And I\'m 100% sure!
  172.         </body></html>
  173.         ''')(aa)
  174.  
  175. def test3():
  176.     test2()
  177.  
  178.     aa=argv()
  179.  
  180.     h=HTML(
  181.         '''\
  182.         <html><head><title>Test of documentation templates</title></head>
  183.         <body>
  184.         <!--#if args-->
  185.           The arguments were:
  186.           <!--#in args size=size end=end-->
  187.               <!--#if previous-sequence-->
  188.                  (<!--#var previous-sequence-start-arg-->-
  189.                   <!--#var previous-sequence-end-arg-->)
  190.               <!--#/if previous-sequence-->
  191.               <!--#if sequence-start-->
  192.                  <dl>
  193.               <!--#/if sequence-start-->
  194.               <dt><!--#var sequence-arg-->.</dt>
  195.               <dd>Argument <!--#var num fmt=d--> was <!--#var arg--></dd>
  196.               <!--#if next-sequence-->
  197.                  (<!--#var next-sequence-start-arg-->-
  198.                   <!--#var next-sequence-end-arg-->)
  199.               <!--#/if next-sequence-->
  200.           <!--#/in args-->
  201.           </dl>
  202.         <!--#else args-->
  203.           No arguments were given.<p>
  204.         <!--#/if args-->
  205.         And I\'m 100% sure!
  206.         </body></html>
  207.         ''')
  208.  
  209.     size,orphan=5,0
  210.     for end in range(20):
  211.         end=end+1
  212.         print '='*60, '\n'
  213.         print h(aa,size=size, orphan=orphan, end=end)
  214.  
  215. def test3_okay(key, val):
  216.     print 'Testing', key
  217.     return 1
  218.  
  219. def test4():
  220.  
  221.     def item(key,**kw): return (key,kw)
  222.     def item2(key,**kw): return kw
  223.  
  224.     class item_class:
  225.         def __init__(self,key,**kw):
  226.             for k in kw.keys(): self.__dict__[k]=kw[k]
  227.  
  228.     items=(
  229.         item( 1,dealer='Bay Chevy', make='Chevrolet', model='Caprice', year=96),
  230.         item( 2,dealer='Bay Chevy', make='Chevrolet', model='Nova', year=96),
  231.         item( 4,dealer='Bay Chevy', make='Chevrolet', model='Nova', year=96),
  232.         item( 5,dealer='Bay Chevy', make='Chevrolet', model='Nova', year=96),
  233.         item( 3,dealer='Bay Chevy', make='Chevrolet', model='Corvett', year=96),
  234.         item( 6,dealer='Bay Chevy', make='Chevrolet', model='Lumina', year=96),
  235.         item( 7,dealer='Bay Chevy', make='Chevrolet', model='Lumina', year=96),
  236.         item( 8,dealer='Bay Chevy', make='Chevrolet', model='Lumina', year=95),
  237.         item( 9,dealer='Bay Chevy', make='Chevrolet', model='Corsica', year=96),
  238.         item(10,dealer='Bay Chevy', make='Chevrolet', model='Corsica', year=96),
  239.         item(11,dealer='Bay Chevy', make='Toyota', model='Camry', year=95),
  240.         item(12,dealer='Colman Olds', make='Olds', model='Ciera', year=96),
  241.         item(12,dealer='Colman Olds', make='Olds', model='Ciera', year=96),
  242.         item(12,dealer='Colman Olds', make='Olds', model='Ciera', year=96),
  243.         item(12,dealer='Colman Olds', make='Olds', model='Cutlass', year=96),
  244.         item(12,dealer='Colman Olds', make='Olds', model='Cutlas', year=95),
  245.         item(12,dealer='Colman Olds', make='Dodge', model='Shadow', year=93),
  246.         item(12,dealer='Colman Olds', make='Jeep', model='Cheroke', year=94),
  247.         item(12,dealer='Colman Olds', make='Toyota', model='Previa', year=92),
  248.         item(12,dealer='Colman Olds', make='Toyota', model='Celica', year=93),
  249.         item(12,dealer='Colman Olds', make='Toyota', model='Camry', year=93),
  250.         item(12,dealer='Colman Olds', make='Honda', model='Accord', year=94),
  251.         item(12,dealer='Colman Olds', make='Honda', model='Accord', year=92),
  252.         item(12,dealer='Colman Olds', make='Honda', model='Civic', year=94),
  253.         item(12,dealer='Colman Olds', make='Honda', model='Civix', year=93),
  254.         item( 1,dealer='Spam Chev', make='Chevrolet', model='Caprice', year=96),
  255.         item( 2,dealer='Spam Chev', make='Chevrolet', model='Nova', year=96),
  256.         item( 4,dealer='Spam Chev', make='Chevrolet', model='Nova', year=96),
  257.         item( 5,dealer='Spam Chev', make='Chevrolet', model='Nova', year=96),
  258.         item( 3,dealer='Spam Chev', make='Chevrolet', model='Corvett', year=96),
  259.         item( 6,dealer='Spam Chev', make='Chevrolet', model='Lumina', year=96),
  260.         item( 7,dealer='Spam Chev', make='Chevrolet', model='Lumina', year=96),
  261.         item( 8,dealer='Spam Chev', make='Chevrolet', model='Lumina', year=95),
  262.         item( 9,dealer='Spam Chev', make='Chevrolet', model='Corsica', year=96),
  263.         item(10,dealer='Spam Chev', make='Chevrolet', model='Corsica', year=96),
  264.         item(11,dealer='Spam Chevy', make='Toyota', model='Camry', year=95),
  265.         item(12,dealer='Spam Olds', make='Olds', model='Ciera', year=96),
  266.         item(12,dealer='Spam Olds', make='Olds', model='Ciera', year=96),
  267.         item(12,dealer='Spam Olds', make='Olds', model='Ciera', year=96),
  268.         item(12,dealer='Spam Olds', make='Olds', model='Cutlass', year=96),
  269.         item(12,dealer='Spam Olds', make='Olds', model='Cutlas', year=95),
  270.         item(12,dealer='Spam Olds', make='Dodge', model='Shadow', year=93),
  271.         item(12,dealer='Spam Olds', make='Jeep', model='Cheroke', year=94),
  272.         item(12,dealer='Spam Olds', make='Toyota', model='Previa', year=92),
  273.         item(12,dealer='Spam Olds', make='Toyota', model='Celica', year=93),
  274.         item(12,dealer='Spam Olds', make='Toyota', model='Camry', year=93),
  275.         item(12,dealer='Spam Olds', make='Honda', model='Accord', year=94),
  276.         item(12,dealer='Spam Olds', make='Honda', model='Accord', year=92),
  277.         item(12,dealer='Spam Olds', make='Honda', model='Civic', year=94),
  278.         item(12,dealer='Spam Olds', make='Honda', model='Civix', year=93),
  279.         )
  280.  
  281.     html=HTML(
  282.         '''\
  283.         <html><head><title>Inventory by Dealer</title></head><body>
  284.           <dl>
  285.           <!--#in inventory mapping size=5 start=first_ad-->
  286.             <!--#if previous-sequence-->
  287.               <!--#in
  288.               previous-batches mapping-->
  289.                 (<!--#var batch-start-var-dealer-->
  290.                  <!--#var batch-start-var-year-->
  291.                  <!--#var batch-start-var-make-->
  292.                  <!--#var batch-start-var-model-->
  293.                  -
  294.                  <!--#var batch-end-var-dealer-->
  295.                  <!--#var batch-end-var-year-->
  296.                  <!--#var batch-end-var-make-->
  297.                  <!--#var batch-end-var-model-->
  298.                  )
  299.               <!--#/in previous-batches-->
  300.             <!--#/if previous-sequence-->
  301.             <!--#if first-dealer-->
  302.               <dt><!--#var dealer--></dt><dd>
  303.             <!--#/if first-dealer-->
  304.             <!--#var year--> <!--#var make--> <!--#var model--> <p>
  305.             <!--#if last-dealer-->
  306.               </dd>
  307.             <!--#/if last-dealer-->
  308.             <!--#if next-sequence-->
  309.               <!--#in next-batches mapping-->
  310.                 (<!--#var batch-start-var-dealer-->
  311.                  <!--#var batch-start-var-year-->
  312.                  <!--#var batch-start-var-make-->
  313.                  <!--#var batch-start-var-model-->
  314.                  -
  315.                  <!--#var batch-end-var-dealer-->
  316.                  <!--#var batch-end-var-year-->
  317.                  <!--#var batch-end-var-make-->
  318.                  <!--#var batch-end-var-model-->
  319.                  )
  320.               <!--#/in next-batches-->
  321.             <!--#/if next-sequence-->
  322.             <!--#/in inventory-->
  323.           </dl>
  324.         </body></html>
  325.         ''')
  326.  
  327.     print html(inventory=items, first_ad=15)
  328.  
  329. def test5():
  330.     html=HTML(
  331.         '''\
  332.         <html><head><title>Affiliate Manager Affiliate Menu</title></head><body>
  333.  
  334.         <CENTER>
  335.         <FONT SIZE="+2">Affiliate Manager Menu</FONT>
  336.         <p>
  337.         
  338.         <!--#if affiliates-->
  339.         Select an affiliate to visit:<br>
  340.         <UL>
  341.         <!--#in affiliates-->
  342.            <LI><A HREF="<!--#var URL1-->/<!--#var ID-->/">
  343.                <!--#var name--></A></LI>
  344.            <!--#/in affiliates-->
  345.         </UL>
  346.         
  347.         <!--#/if affiliates-->
  348.  
  349.         <p>
  350.         <A HREF="<!--#var URL1-->/add_affiliate_form">Add an affiliate</A>
  351.         
  352.         <!--#if affiliates-->
  353.         * <A HREF="<!--#var URL1-->/delete_affiliates_form">
  354.         Delete affiliates</A>
  355.         <!--#/if affiliates-->
  356.  
  357.         </p>
  358.         </CENTER>
  359.         </body>
  360.         
  361.         </html>''')
  362.  
  363.     print html(affiliates=[], URL1='www')
  364.  
  365. def test6():
  366.     def d(**kw): return kw
  367.     data=(d(name='jim', age=38),
  368.           # d(name='kak', age=40),
  369.           d(name='will', age=7),
  370.           d(name='drew', age=4),
  371.           d(name='ches', age=1),
  372.           )
  373.     html=HTML(
  374.         """Ages:\n
  375.         <!--#in data mapping-->
  376.           <!--#if sequence-end-->
  377.              ---------------
  378.              for variable name:
  379.              min:    <!--#var min-name-->
  380.              max:    <!--#var max-name-->
  381.              count:  <!--#var count-name-->
  382.              total:  <!--#var total-name-->
  383.              median: <!--#var median-name-->
  384.              ---------------
  385.              for variable age:
  386.              min:    <!--#var min-age-->
  387.              max:    <!--#var max-age-->
  388.              count:  <!--#var count-age-->
  389.              total:  <!--#var total-age-->
  390.              median: <!--#var median-age-->
  391.              mean:   <!--#var mean-age-->
  392.              s.d.    <!--#var standard-deviation-age-->
  393.              ---------------
  394.           <!--#/if sequence-end-->
  395.         <!--#/in data-->
  396.         """)
  397.     print html(data=data)
  398.  
  399. def test7():
  400.     import DateTime
  401.     html=HTML("""
  402.     <!--#var name capitalize spacify--> is
  403.     <!--#var date fmt=year-->/<!--#var date fmt=month-->/<!--#var date fmt=day-->
  404.     """)
  405.     html.names({'name':'name', 'date':'date'})
  406.     print html(date=DateTime.DateTime(),
  407.                name='todays_date')
  408.  
  409. def test8():
  410.     import DateTime
  411.     html=String("""
  412.     %(name capitalize spacify)s is
  413.     %(date fmt=year)s/%(date fmt=month)s/%(date fmt=day)s
  414.     """)
  415.     print html(date=DateTime.DateTime(),
  416.                name='todays_date')
  417.  
  418. def test9():
  419.     html=HTML(
  420.         """
  421. <!--#in spam-->
  422. <!--#in sequence-item-->
  423.    <!--#var sequence-item-->
  424. <!--#/in sequence-item-->
  425. <!--#/in spam-->
  426.         """)
  427.     print html(spam=[[1,2,3],[4,5,6]])
  428.  
  429. def test9a():
  430.     html=HTML(
  431.         """
  432.         <!--#in spam-->
  433.            <!--#in sequence-item-->
  434.               <!--#var sequence-item-->
  435.            <!--#/in sequence-item-->
  436.         <!--#/in spam-->
  437.         """)
  438.     print html(spam=[[1,2,3],[4,5,6]])
  439.  
  440. def test10():
  441.     #import Missing
  442.     html=HTML(
  443.         """
  444.               <!--#var spam fmt="$%.2f bob's your uncle" null="spam%eggs!|"-->
  445.         """) #'
  446.     print html(spam=42)
  447.     print html(spam=None)
  448.     #print html(spam=Missing.Value)
  449.     
  450.  
  451. def test11():
  452.     #import Missing
  453.     html=HTML(
  454.         """
  455.                   <!--#var spam -->
  456.         html:     <!--#var spam fmt=html-quote-->
  457.         url:      <!--#var spam fmt=url-quote-->
  458.         multi:    <!--#var spam fmt=multi-line-->
  459.         dollars:  <!--#var spam fmt=whole-dollars-->
  460.         cents:    <!--#var spam fmt=dollars-and-cents-->
  461.         dollars,: <!--#var spam fmt=dollars-with-commas-->
  462.         cents,:   <!--#var spam fmt=dollars-and-cents-with-commas-->
  463.  
  464.         """)
  465.     
  466.     print html(spam=4200000)
  467.     print html(spam=None)
  468.     print html(spam='<a href="spam">\nfoo bar')
  469.     # print html(spam=Missing.Value)
  470.     
  471.  
  472. class test12ob:
  473.     def __init__(self,**kw):
  474.         for k,v in kw.items(): self.__dict__[k]=v
  475.     def puke(self):
  476.         raise 'Puke', 'raaalf'
  477.  
  478. def test12():
  479.     class foo:
  480.         def __len__(self): return 9
  481.         def __getitem__(self,i):
  482.             if i >= 9: raise IndexError, i
  483.             return test12ob(index=i, value='item %s' % i)
  484.  
  485.     html=HTML(
  486.         """
  487.         <!--#if spam-->
  488.         <!--#in spam-->
  489.            <!--#var value-->
  490.            <!--#var puke-->
  491.         <!--#/in spam-->
  492.         <!--#/if spam-->
  493.         """)
  494.     try: print html(spam=foo())
  495.     except: return
  496.     raise 'DocumentTemplate bug', (
  497.         'Puke error not properly propigated in test 12')
  498.    
  499. def test13():
  500.    "Test automatic rendering of callable obnjects"
  501.    class C:
  502.       x=1
  503.       def y(self): return self.x*2
  504.       h=HTML("The h method, <!--#var x--> <!--#var y-->")
  505.       h2=HTML("The h2 method")
  506.  
  507.    print HTML("<!--#var x-->, <!--#var y-->, <!--#var h-->")(C())
  508.    print HTML(
  509.       """
  510.       <!--#var expr="_.render(i.x)"-->, 
  511.       <!--#var expr="_.render(i.y)"-->, 
  512.       <!--#var expr="_.render(i.h2)"-->""")(i=C())
  513.  
  514. def test14():
  515.     # test with tag
  516.     class person:
  517.         name='Jim'
  518.         height_inches=73
  519.  
  520.     print HTML("""<!--#with person-->
  521.     Hi, my name is <!--#var name-->
  522.     My height is <!--#var "height_inches*2.54"--> centimeters.
  523.     <!--#/with-->""")(person=person)
  524.  
  525. def test15():
  526.     # test raise tag
  527.     try:
  528.         print HTML("""<!--#raise IndexError-->
  529.         The raise tag test suceeded!
  530.         <!--#/raise-->""")()
  531.     except IndexError, v:
  532.         print v
  533.  
  534. def main():
  535.         import traceback
  536.         print 'Test 1', '='*60
  537.         try: test1()
  538.         except: traceback.print_exc()
  539.         print 'Test 2', '='*60
  540.         try: test2()
  541.         except: traceback.print_exc()
  542.         print 'Test 3', '='*60
  543.         try: test3()
  544.         except: traceback.print_exc()
  545.         print 'Test 4', '='*60
  546.         try: test4()
  547.         except: traceback.print_exc()
  548.         print 'Test 5', '='*60
  549.         try: test5()
  550.         except: traceback.print_exc()
  551.         print 'Test 6', '='*60
  552.         try: test6()
  553.         except: traceback.print_exc()
  554.         print 'Test 9', '='*60
  555.         try: test9()
  556.         except: traceback.print_exc()
  557.         print 'Test 9a', '='*60
  558.         try: test9a()
  559.         except: traceback.print_exc()
  560.         print 'Test 10', '='*60
  561.         try: test10()
  562.         except: traceback.print_exc()
  563.         print 'Test 11', '='*60
  564.         try: test11()
  565.         except: traceback.print_exc()
  566.         print 'Test 14', '='*60
  567.         try: test14()
  568.         except: traceback.print_exc()
  569.         print 'Test 15', '='*60
  570.         try: test15()
  571.         except: traceback.print_exc()
  572.     
  573.  
  574. if __name__ == "__main__":
  575.     try: command=sys.argv[1]
  576.     except: command='main'
  577.     globals()[command]()
  578.